<!DOCTYPE html>
<html lang="en">

    <head>

        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">

        <title>Bem vindo ao {APP_NAME}</title>

        <!-- Bootstrap Core CSS -->
        <link href="view/css/bootstrap.min.css" rel="stylesheet">

        <!-- MetisMenu CSS -->
        <link href="view/css/plugins/metisMenu/metisMenu.min.css" rel="stylesheet">

        <!-- Custom CSS -->
        <link href="view/css/sb-admin-2.css" rel="stylesheet">

        <!-- Custom Fonts -->
        <link href="view/font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
            <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
            <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->

    </head>

    <body>

        <div class="container">
            <div class="row">
                <div class="col-md-4 col-md-offset-4">
                    <div class="login-panel panel panel-default">
                        <div class="panel-heading">
                            <h3 class="panel-title">Bem vindo ao {APP_NAME}</h3>
                        </div>
                        <div class="panel-body">
                            <form id="form" role="form">
                                <fieldset>
                                    <div class="form-group">
                                        <input class="form-control" placeholder="E-mail" name="login" type="email" autofocus>
                                    </div>
                                    <div class="form-group">
                                        <input id="senha"  class="form-control" placeholder="senha" name="pass" type="password" value="">
                                        
                                    </div>
                                    <div class="checkbox">
                                        <label>
                                            <input name="remember" type="checkbox" value="Remember Me">Lembrar - me
                                        </label>
                                    </div>
                                  
                                    <div id="btnLogar" class="btn btn-lg btn-success btn-block">Logar</div>


                                </fieldset><br>
                                <div id="msg2" class="alert alert-success" style="display:none">
                                    Logado com sucesso, Você será redirecionado para o painel de controle.
                                </div>
                                <div id="msg" class="alert alert-danger" style="display:none">
                                    Usuario ou senha incorretos <a class="alert-link" href="#"></a>.
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- jQuery Version 1.11.0 -->
        <script src="view/js/jquery-1.11.0.js"></script>

        <!-- Bootstrap Core JavaScript -->
        <script src="view/js/bootstrap.min.js"></script>

        <!-- Metis Menu Plugin JavaScript -->
        <script src="view/js/plugins/metisMenu/metisMenu.min.js"></script>

        <!-- Custom Theme JavaScript -->
        <script src="view/js/sb-admin-2.js"></script>
        <script src="view/js/jquery.validate.js"></script>
        
                <script type="text/javascript">
            $(document).ready(function() {
                
            $("input").keypress(function(event) {
                if (event.which == 13) { //tecla enter
                    executaJson();
                }
            });

        $('#btnLogar').click(executaJson);//quando clicar 
        
                
                $("#form").validate({
                     rules: {
                         login: {required: true, minlength: 3},
                         pass: {ipAddress: false, required: true}   
                     },
                     messages: {
                         login: "Insira seu e-mail",
                         pass: "Insira sua senha"
                     },
                     highlight: function(element) {
                         $(element).closest('.form-group').removeClass('has-success').addClass('has-error');
                     },
                     success: function(element) {
                         $(element).closest('.form-group').removeClass('has-error').addClass('has-success');
                     },
                     errorClass: 'help-block'
                });
                        function executaJson(){
           if ($('#form').valid()) { //validação
                $.post("./modules/mod-login/verifica-login.php?action=verifica",
                    $("#form").serialize(),
                        function(data) {
                            if (data.logou == 1) {
                               $("#msg").fadeOut(600);
                               $("#msg2").fadeIn(600);
                               setTimeout("location.href = 'index.php?p=registrar';",3500);
                            } else {
                                $("#msg").fadeIn(600);
                            }
                    }, "json");//trata dados retorno em json
            }else{          
                return false; 
            }
        }
            });
        </script>
    </body>

</html>
